package com.example.hibernate.program;

import java.util.Iterator;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

public class Driver {

	public static void main(String[] args) {
		SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
		Session session = sessionFactory.openSession();
		Transaction transaction = session.beginTransaction();
		try {
//			Employee employee = new Employee();
//			employee.setFirstName("Önder");
//			employee.setLastName("ŞAHİN");
//			employee.setEmail("crazyboy1234@gmail.com");
//			{
//				Project project = new Project();
//				project.setName("Bugün ne giysem?");
//				session.save(project);
//				employee.getProjects().add(project);
//			}
//			{
//				Project project = new Project();
//				project.setName("Bu tarz benim.");
//				session.save(project);
//				employee.getProjects().add(project);
//			}
//			session.save(employee);
			
			Project project = (Project) session.get(Project.class, 2L);
			Iterator<Employee> iterator = project.getEmployees().iterator();
			while (iterator.hasNext()) {
				Employee employee = iterator.next();
				System.out.println(employee);
			}

			transaction.commit();
		} catch (Exception e) {
			transaction.rollback();
		}
		session.close();
		sessionFactory.close();
	}
}
